<?php

 class BaseColumnFamily extends PandraColumnFamily {

	public function __construct($keySpace) {
		$this->setKeySpace($keySpace);
		parent::__construct();
	}

	public function saveColumns($keyID, $columns) {
		$this->setKeyID($keyID);
		if (is_array($columns) && count($columns) > 0) {
			foreach ($columns as $name => $value) {
				$this->setColumn($name, $value);
			}
		}
		return $this->save();
	}

	public function addColumnWithValue($name, $value, $type) {
		$col = new PandraColumn($name, $type);
		$col->setValue($value);
		$this->addColumnObj($col);
		return $this->save();
	}

	public function getColumnParent() {
		// Specify what Column Family to query against.
  		$columnParent = new cassandra_ColumnParent();
  		$columnParent->column_family = $this->getName();
  		$columnParent->super_column = NULL;

  		return $columnParent;
	}

	public function loadColumnsSlice($limit, &$offset = "", $isReversed = false){
		if ($this->getKeyID() != null) {
			$this->setLimit($limit + 1);
			$this->setReversed($isReversed);
			$this->setStart($offset);
			$this->setFinish("");
			if ($this->load()) {
				if ($this->count() > $limit) {
					$lastCol = array_pop($this->_columns);
					$offset = $lastCol->getName();
				}
				return true;
			}

		}
		return false;
	}
 }